// Copyright (c) 2011, Grant China
// All rights reserved.

package org.gwtlcars.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class LcarsRoundButton extends Composite implements HasClickHandlers {

    private static LcarsRoundButtonUiBinder uiBinder = GWT
            .create(LcarsRoundButtonUiBinder.class);

    interface LcarsRoundButtonUiBinder extends
            UiBinder<Widget, LcarsRoundButton> {
    }

    @UiField
    Button button;

    private ClickHandler click_handler = null;
    private String color = LcarsColor.LIGHT_ORANGE;

    public LcarsRoundButton(String button_text) {
        initWidget(uiBinder.createAndBindUi(this));
        button.setText(button_text);
        button.addStyleName(color);
    }

    @UiHandler("button")
    void onClick(ClickEvent e) {
        if (click_handler != null)
            click_handler.onClick(e);
    }

    @Override
    public HandlerRegistration addClickHandler(ClickHandler handler) {
        click_handler = handler;
        return null;
    }

    public void setColor(String c) {
        button.removeStyleName(color);
        color = c;
        button.addStyleName(color);
    }
}
